package com.crm.system.controller.cluePoolManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.system.service.cluePoolManager.CluePoolStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * 线索池数据统计
 * @author luojie
 * @date 2021/2/2 10:09
 */
@RestController
@RequestMapping("/cluePoolStatistics")
@Slf4j
public class CluePoolStatisticsController {

    @Autowired
    CluePoolStatisticsService cluePoolStatisticsService;

    /**
     * 线索池数据统计-统计左侧数量
     * @param cluePoolId
     * @return
     */
    @GetMapping("/cluePoolLeftStatistics")
    public DataResponse cluePoolLeftStatistics(@RequestParam String cluePoolId){
        try{
            JSONObject jsonObject = cluePoolStatisticsService.cluePoolLeftStatistics(cluePoolId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),jsonObject);
        }catch(Exception e){
            log.error("cluePoolStatistics cluePoolLeftStatistics error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 统计线索池最近12个月内领取/转化数据
     * @param cluePoolId
     * @return
     */
    @GetMapping("/cluePoolReceiveConversionStatistics")
    public DataResponse cluePoolReceiveConversionStatistics(@RequestParam String cluePoolId,@RequestParam  Integer monthCount) throws ParseException {
            List<JSONObject> jsonObject = cluePoolStatisticsService.cluePoolReceiveConversionStatistics(cluePoolId,monthCount);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),jsonObject);
    }
}
